package com.itheima.project.web;

import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.security.CustomerEnum;
import com.itheima.project.face.CustomerAdapterFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.security.ResourceVo;
import com.itheima.project.vo.security.RoleVo;
import com.itheima.project.vo.security.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CustomerAdapterController.java
 * @Description 客户适配controller
 */
@RestController
@RequestMapping("customer-adapter")
@Api(tags = "客户适配controller")
@Slf4j
public class CustomerAdapterController {

    @Autowired
    CustomerAdapterFace customerAdapterFace;

    /**
     * @Description 按客户名查找客户
     * @param customername 登录名
     * @return
     */
    @GetMapping("find-customer-customername-enterprise/{customername}/{enterpriseId}")
    @ApiOperation(value = "按客户名查找客户",notes = "按客户名查找客户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",name = "customername",value = "客户名称",dataType = "String"),
            @ApiImplicitParam(paramType = "path",name = "enterpriseId",value = "企业id",dataType = "Long")
    })
    ResponseWrap<UserVo> findCustomerByUsernameAndEnterpriseId(@PathVariable("customername") String customername,
                                                               @PathVariable("enterpriseId") Long enterpriseId){
        UserVo userVo = customerAdapterFace.findCustomerByUsernameAndEnterpriseId(customername, enterpriseId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,userVo);
    }

    /**
     * @Description 按客户手机查找客户
     * @param mobile 登录名
     * @return
     */
    @GetMapping("find-customer-mobile-enterprise/{mobile}/{enterpriseId}")
    @ApiOperation(value = "按客户手机查找客户",notes = "按客户手机查找客户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",name = "mobile",value = "客户手机",dataType = "String"),
            @ApiImplicitParam(paramType = "path",name = "enterpriseId",value = "企业id",dataType = "Long")
    })
    ResponseWrap<UserVo> findCustomerByMobileAndEnterpriseId(@PathVariable("mobile")String mobile,
                                               @PathVariable("enterpriseId")Long enterpriseId){
        UserVo userVo = customerAdapterFace.findCustomerByMobileAndEnterpriseId(mobile, enterpriseId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,userVo);
    }

    /**
     * @Description 按微信openId查找客户
     * @param openId 登录名
     * @return
     */
    @ApiOperation(value = "按客户openid查找客户",notes = "按客户openid查找客户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",name = "openId",value = "客户openid",dataType = "String"),
            @ApiImplicitParam(paramType = "path",name = "enterpriseId",value = "企业id",dataType = "Long")
    })
    @GetMapping("find-customer-openid-enterprise/{openId}/{enterpriseId}")
    ResponseWrap<UserVo> findCustomerByOpenIdAndEnterpriseId(@PathVariable("openId")String openId,
                                                             @PathVariable("enterpriseId")Long enterpriseId){
        UserVo userVo = customerAdapterFace.findCustomerByOpenIdAndEnterpriseId(openId, enterpriseId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,userVo);
    }

    /**
     * @Description 查找客户所有角色
     * @param customerId 客户Id
     * @return
     */
    @GetMapping("find-role-customer/{customerId}")
    @ApiOperation(value = "查找客户所有角色",notes = "查找客户所有角色")
    @ApiImplicitParam(paramType = "path",name = "customerId",value = "客户id",dataType = "Long")
    ResponseWrap<List<RoleVo>> findRoleByCustomerId(@PathVariable("customerId")Long customerId){
        List<RoleVo> roleVos = customerAdapterFace.findRoleByCustomerId(customerId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,roleVos);
    }

    /**
     * @Description 查询客户有资源
     * @param customerId 客户Id
     * @return
     */
    @GetMapping("find-resoure-customer/{customerId}")
    @ApiOperation(value = "查询客户有资源",notes = "查询客户有资源")
    @ApiImplicitParam(paramType = "path",name = "customerId",value = "客户id",dataType = "Long")
    ResponseWrap<List<ResourceVo>> findResourceByCustomerId(@PathVariable("customerId")Long customerId){
        List<ResourceVo> resourceVos = customerAdapterFace.findResourceByCustomerId(customerId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,resourceVos);
    }

    /***
     * @description 查询当前客户
     * @param customerId
     * @return
     */
    @GetMapping("find-cuttent-customer/{customerId}")
    @ApiOperation(value = "查询当前客户",notes = "查询当前客户")
    @ApiImplicitParam(paramType = "path",name = "customerId",value = "客户id",dataType = "Long")
    ResponseWrap<UserVo> findCurrentCustomer(@PathVariable("customerId")Long customerId){
        UserVo userVo = customerAdapterFace.findCurrentCustomer(customerId);
        return ResponseWrapBuild.build(CustomerEnum.SUCCEED,userVo);
    }
}
